/************************************************************
wx
2020/1/17

*************************************************************/

using System.Collections.Generic;
using UnityEngine;

namespace Fight
{
    public class FightManager : Singleton<FightManager>
    {
        public Round CurRound { get; private set; }
        public RoundHolder CurHolder { get; private set; }

        private Character m_mainCharacter;
        private Character m_monster;

        private FightManager()
        {

        }

        /// <summary>
        /// 战斗开始
        /// </summary>
        public Round FightStart(Character main, Character monster)
        {
            if (main == null || monster == null)
            {
                Debug.LogError("角色数据空");
                return null;
            }
            m_mainCharacter = main;
            m_monster = monster;
            m_mainCharacter.ResetOnFightStart();
            m_monster.ResetOnFightStart();
            CurHolder = RoundHolder.MainChaRound;
            CurRound = new Round(m_mainCharacter,m_monster);
            CurRound.RoundStart();
            return CurRound;
        }

        public void FightExit()
        {
            m_monster = null;
            m_mainCharacter = null;
            CurRound = null;
        }

        public Round NextRound()
        {
            CurHolder = GetNextHolder();
            CurRound.RoundEnd();
            switch (CurHolder)
            {
                case RoundHolder.MainChaRound:
                {
                    CurRound = new Round(m_mainCharacter,m_monster);
                    CurRound.RoundStart();
                }
                    break;
                case RoundHolder.MonsterRound:
                {
                    CurRound = new Round(m_monster,m_mainCharacter);
                    CurRound.RoundStart();
                }
                    break;
            }

            return CurRound;
        }

        /// <summary>
        /// 出卡
        /// </summary>
        public bool PlayCard()
        {
            if (CurRound != null)
            {
                return CurRound.Play();
            }

            return false;
        }

        private RoundHolder GetNextHolder()
        {
            if (CurRound != null && CurHolder == RoundHolder.MonsterRound)
            {
                return RoundHolder.MainChaRound;
            }

            return RoundHolder.MonsterRound;
        }
    }
}

